var util = require('../../utils/util.js');
var ajax = require('../../utils/ajax.js');

var sliderWidth = 96; // 需要设置slider的宽度，用于计算中间位置

Page({
    data: {
        dataLoaded:false,

        tabs: ["资金流水", "提现记录"],
        activeIndex: 0,
        sliderOffset: 0,
        sliderLeft: 0,

        money: 0.00,
        payCount:0,
        waterList: [],
        txList: [],
    },
    onLoad: function() {
        var that = this;

        wx.getSystemInfo({
            success: function(res) {
                that.setData({
                    sliderLeft: (res.windowWidth / that.data.tabs.length - sliderWidth) / 2,
                    sliderOffset: res.windowWidth / that.data.tabs.length * that.data.activeIndex
                });
            }
        });
    },

    onShow(){
        this._getUserInfo();
        this._getWaterList();
        this._getTxList();
    },

    tabClick: function(e) {
        this.setData({
            sliderOffset: e.currentTarget.offsetLeft,
            activeIndex: e.currentTarget.id
        });
    },

    //用户信息
    _getUserInfo() {
        var _self = this;

        ajax.P('/openapi/User/getUserInfo', {}, function(d) {
            _self.setData({
                money: d.result.userInfo.money,
                dataLoaded: true,
                payCount:d.result.payCount
            });
        });
    },

    //资金流水
    _getWaterList() {
        var _self = this;

        ajax.P('/openapi/User/userFinanceLog', {
            page: 1,
        }, function(d) {
            _self.setData({
                waterList: d.result.financeList
            });
        });
    },

    //提现记录
    _getTxList() {
        var _self = this;

        ajax.P('/openapi/User/getUserWithdraw', {
            page: 1,
        }, function(d) {
            _self.setData({
                txList: d.result.withdrawList
            });
        });
    },


    _tx: function() {
        wx.navigateTo({
            url: '/pages/tx/tx'
        });
    },
    _goComplain:function(){
        wx.navigateTo({
            url: '/pages/complain/complain'
        });
    }
});